package com.yellowpage.omc.datacollect.action;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.yellowpage.white.common.Configuration;
import com.yellowpage.white.common.Constants;
import com.yellowpage.white.struts.BaseAction;
import com.yellowpage.white.struts.Module;
import com.yellowpage.white.struts.OperationType;
import com.yellowpage.white.util.Util4Java;

import com.yellowpage.omc.datacollect.data.DataCollectImportLog;
import com.yellowpage.omc.datacollect.service.DataCollectImportLogService;

public class DataCollectImportLogAction extends BaseAction {

	public String RESULT_QUERY = "query";
	public String RESULT_ADD = "add";
	public String RESULT_EDIT = "edit";

	private Configuration configuration;

	public void setConfiguration(Configuration configuration) {
		this.configuration = configuration;
	}

	private List<DataCollectImportLog> dataCollectImportLogList = new ArrayList<DataCollectImportLog>();
	private List<Map> resultList = new ArrayList<Map>();

	private DataCollectImportLog dataCollectImportLog;
	private DataCollectImportLogService dataCollectImportLogService;

	private String selectedId;
	private String[] selectedIds;
	private String message;

	private String query_importLogId;
	private String query_dataCollectId;
	private String query_dataCollectBatchId;

	private String query_batchNum;
	private String query_seq;
	
	private String query_event;
	private String query_createUser;
	private String query_createTime;
	private String query_content;

	public void prepare() {
		super.prepare();

		if (this.selectedId != null && !this.selectedId.equals("")) {
			this.dataCollectImportLog = dataCollectImportLogService
					.getDataCollectImportLog(Long.parseLong(selectedId));
		}
	}

	public String queryByPage() {
		initPageRender();

		Map queryMap = new HashMap();
		
		queryMap.put("batchNum", query_batchNum);
		queryMap.put("seq", query_seq);
		queryMap.put("importLogId", query_importLogId);
		queryMap.put("dataCollectId", query_dataCollectId);
		queryMap.put("dataCollectBatchId", query_dataCollectBatchId);
		queryMap.put("seq", query_seq);
		queryMap.put("event", query_event);
		queryMap.put("createUser", query_createUser);
		queryMap.put("createTime", query_createTime);
		queryMap.put("content", query_content);

		resultList = dataCollectImportLogService
				.queryDataCollectImportLogByPage(queryMap, pageRender);

		setPageRenderToRequest();

		return RESULT_QUERY;
	}

	public String toAdd() {
		return RESULT_ADD;
	}

	public String save() {

		dataCollectImportLogService
				.saveDataCollectImportLog(dataCollectImportLog);

		message = "新增成功!";
		return RESULT_ADD;
	}

	public void validateSave() {
		if (dataCollectImportLog.getEvent().length() == 0) {
			this.addActionError("** Event 不能为空 !");
		}
		if (dataCollectImportLog.getContent().length() == 0) {
			this.addActionError("** Content 不能为空 !");
		}

		this.setValidatorResult("/omc/datacollect/DataCollectImportLogAdd.jsp");
	}

	public String toEdit() {
		Long id = new Long(selectedId);

		dataCollectImportLog = dataCollectImportLogService
				.getDataCollectImportLog(id);

		return RESULT_EDIT;
	}

	public String update() {

		dataCollectImportLogService
				.updateDataCollectImportLog(dataCollectImportLog);

		message = "修改成功!";

		return RESULT_EDIT;
	}

	public void validateUpdate() {
		if (dataCollectImportLog.getEvent().length() == 0) {
			this.addActionError("** Event 不能为空 !");
		}
		if (dataCollectImportLog.getContent().length() == 0) {
			this.addActionError("** Content 不能为空 !");
		}
		this.setValidatorResult("/omc/datacollect/DataCollectImportLogUpdate.jsp");
	}

	public String delete() {
		List ids = new ArrayList();

		for (String id : selectedIds) {
			ids.add(Long.valueOf(id));
		}

		try {
			this.dataCollectImportLogService.delete(ids);
		} catch (Exception e) {
			System.out.println("异常....");
			this.addActionError("** 可能含有子记录约束冲�?删除失败 !");
		}

		return queryByPage();
	}

	/**
	 * getters and setters
	 * 
	 * @return
	 */
	public void setDataCollectImportLog(
			DataCollectImportLog dataCollectImportLog) {
		this.dataCollectImportLog = dataCollectImportLog;
	}

	public DataCollectImportLog getDataCollectImportLog() {
		return dataCollectImportLog;
	}

	public void setDataCollectImportLogService(
			DataCollectImportLogService dataCollectImportLogService) {
		this.dataCollectImportLogService = dataCollectImportLogService;
	}

	public List<DataCollectImportLog> getDataCollectImportLogList() {
		return dataCollectImportLogList;
	}

	public void setDataCollectImportLogList(
			List<DataCollectImportLog> dataCollectImportLogList) {
		this.dataCollectImportLogList = dataCollectImportLogList;
	}

	public String getSelectedId() {
		return selectedId;
	}

	public void setSelectedId(String selectedId) {
		this.selectedId = selectedId;
	}

	public String[] getSelectedIds() {
		return selectedIds;
	}

	public void setSelectedIds(String[] selectedIds) {
		this.selectedIds = selectedIds;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public List<Map> getResultList() {
		return resultList;
	}

	public void setResultList(List<Map> resultList) {
		this.resultList = resultList;
	}

	public String getQuery_importLogId() {
		return this.query_importLogId;
	}

	public void setQuery_importLogId(String importLogId) {
		this.query_importLogId = importLogId;
	}

	public String getQuery_dataCollectId() {
		return this.query_dataCollectId;
	}

	public void setQuery_dataCollectId(String dataCollectId) {
		this.query_dataCollectId = dataCollectId;
	}

	public String getQuery_dataCollectBatchId() {
		return this.query_dataCollectBatchId;
	}

	public void setQuery_dataCollectBatchId(String dataCollectBatchId) {
		this.query_dataCollectBatchId = dataCollectBatchId;
	}

	public String getQuery_seq() {
		return this.query_seq;
	}

	public void setQuery_seq(String seq) {
		this.query_seq = seq;
	}

	public String getQuery_event() {
		return this.query_event;
	}

	public void setQuery_event(String event) {
		this.query_event = event;
	}

	public String getQuery_createUser() {
		return this.query_createUser;
	}

	public void setQuery_createUser(String createUser) {
		this.query_createUser = createUser;
	}

	public String getQuery_createTime() {
		return this.query_createTime;
	}

	public void setQuery_createTime(String createTime) {
		this.query_createTime = createTime;
	}

	public String getQuery_content() {
		return this.query_content;
	}

	public void setQuery_content(String content) {
		this.query_content = content;
	}

	public String getQuery_batchNum() {
		return query_batchNum;
	}

	public void setQuery_batchNum(String query_batchNum) {
		this.query_batchNum = query_batchNum;
	}

}
